In [1]:
import pandas as pd
from bokeh.models import Plot, Rect, Range1d, HoverTool, Patch, Patches, ColumnDataSource, TapTool
PLOT_FORMATS = dict(x_range=Range1d(0,100), y_range=Range1d(0,100), plot_width=200, plot_height=50, min_border=0, toolbar_location=None)

In [2]:
from bokeh.plotting import output_notebook, show
output_notebook()


BokehJS successfully loaded.

In [3]:
plot = Plot(**PLOT_FORMATS)
plot.add_glyph(Rect(x=50, y=50, width=100, height=100))
plot.add_tools(HoverTool())
show(plot)


Does NOT work - hover on Patch

console error - "Bokeh: 'point' selection not available for Patch"


In [4]:
patch_data = pd.DataFrame(
    {
        'patch'  : [0, 0, 100, 100],
    }, 
    index= [0, 100, 100, 0]
)
patch_data_source = ColumnDataSource(patch_data)
plot_patch = Plot(**PLOT_FORMATS)
plot_patch.add_glyph(patch_data_source, Patch(x='index', y='patch', fill_color='red'))
plot_patch.add_tools(HoverTool(tooltips='Hello world'))
show(plot_patch)


Does work - hover on Patches


In [5]:
patches_data = pd.DataFrame(
    {
        'xs'  : [[0, 100, 100, 0],],
        'ys'  : [[0, 0, 100, 100],],
        'value': ['Yay!']
    }, 
)
plot_patches = Plot(**PLOT_FORMATS)
plot_patches.add_glyph(ColumnDataSource(patches_data), Patches(xs='xs', ys='ys', fill_color='green'))
plot_patches.add_tools(HoverTool(tooltips='@value'))
show(plot_patches)


Does work - Hover on two patches


In [6]:
patches_two_data = pd.DataFrame(
    {
        'xs'  : [[0, 50, 50, 0],[50, 100, 100, 50]],
        'ys'  : [[0, 0, 100, 100],[0, 0, 100, 100]],
        'value': ['Patches 1', 'Patches 2']
    }, 
)
plot_patches_two = Plot(**PLOT_FORMATS)
plot_patches_two.add_glyph(ColumnDataSource(patches_two_data), Patches(xs='xs', ys='ys', fill_color='green'))
plot_patches_two.add_tools(HoverTool(tooltips='@value'))
show(plot_patches_two)


Hover on discontinuous patches


In [14]:
from numpy import NAN
patches_dis_data = pd.DataFrame(
    {
        'xs'  : [[0, 50, 50, 0, NAN, 50, 90, 90, 50], [90, 100, 100, 90]],
        'ys'  : [[0, 0, 100, 100, NAN, 0, 0, 100, 100], [0, 0, 100, 100]],
        'value': ['I am sad', 'I can hover'],
        'fill_color': ['red', 'green']
    }, 
)
plot_patches_dis = Plot(**PLOT_FORMATS)
plot_patches_dis.add_glyph(ColumnDataSource(patches_dis_data), Patches(xs='xs', ys='ys', fill_color='fill_color'))
plot_patches_dis.add_tools(HoverTool(tooltips='@value'))
plot_patches_dis.add_tools(TapTool())
show(plot_patches_dis)



In [10]:
from bokeh.io import output_file
output_file?

In [ ]: